package com.video.netty.InChannelHandler;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.video.entity.Record;
import com.video.service.webcon.IRecordService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * golang保存会议录像,host发起方，type会议类型（1.一对一，2.多方讨论，3.主麦模式），record录像文件名，users参与终端，golang发送
 *
 * {"id":"saveRecord", "host":"1", "type":"1", "starttime":"2019-12-17 23:36:38",
 *  "endtime":"2019-12-17 23:36:38", "record":"1_2018-12-03_14-54-39.webm", "users":["1", "3", "7"]}
 */
@BaseChannelHandler.MsgHandler
public class WsSaveRecordChannelHandler extends BaseChannelHandler {

    @Autowired
    private IRecordService recordService;

    @Override
    protected String msgId() {
        return "saveRecord";
    }

    @Override
    protected void msgHandler(JSONObject json) throws Exception {
        Record record = JSON.parseObject(json.toJSONString(), Record.class);
        recordService.insertRecord(record);
    }
}
